package com.mocha.websocket;

import com.mocha.websocket.command.MochaCommandEnum;
import com.mocha.websocket.handler.*;
import com.mocha.websocket.metadata.MochaSocketConfigProperties;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;

/**
 * @author: songkui
 * @since: 2023/2/23 10:30
 */
@Slf4j
@NoArgsConstructor
public class MochaWSMetadataBuilder {

    public static MochaWSMetadataBuilder builder(){
        return new MochaWSMetadataBuilder();
    }

    public MochaWSMetadataBuilder connectHandler(MochaConnectHandler connectHandler) {
        HandlerMapping.initializeConnectHandler(connectHandler);
        return this;
    }

    public MochaWSMetadataBuilder closeHandler(MochaCloseHandler closeHandler) {
        HandlerMapping.initializeCloseHandler(closeHandler);
        return this;
    }

    public MochaWSMetadataBuilder userValidHandler(MochaUserValidHandler userValidHandler) {
        HandlerMapping.initializeUserValidHandler(userValidHandler);
        return this;
    }





    public MochaWSMetadataBuilder socketConnectHandler(MochaSocketConnectHandler connectHandler) {
        HandlerMapping.initializeSocketConnectHandler(connectHandler);
        return this;
    }

    public MochaWSMetadataBuilder socketCloseHandler(MochaSocketCloseHandler closeHandler) {
        HandlerMapping.initializeSocketClosetHandler(closeHandler);
        return this;
    }

    public MochaWSMetadataBuilder socketUserValidHandler(MochaSocketUserValidHandler userValidHandler) {
        HandlerMapping.initializeSocketUserValidHandler(userValidHandler);
        return this;
    }



    public MochaWSMetadataBuilder initHandler(Map<Integer, MochaCommandEnum> commandEnumMap, String handlerPackagePath) throws Exception {
        MochaSocketInitialize.initializeCommandModel(commandEnumMap);
        MochaSocketInitialize.initializeHandlerMapping(handlerPackagePath, commandEnumMap);
        return this;
    }

    public void start() {
        log.info("Mocha WebSocket is start");
    }

    public void start(MochaSocketConfigProperties configProperties) {
        MochaWebSocketServer socketServer = new MochaWebSocketServer();
        socketServer.start(configProperties);
    }


}
